package cn.melonlib.cores.commons.comp.web.utils;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.ajp.AbstractAjpProtocol;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

@Configuration
public class WebConfig {

    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        return f->f.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,"/index.html"));
    }

//    @Bean
//    @ConditionalOnProperty(value = "web.server.container",havingValue = "tomcat",matchIfMissing = true)
//    public TomcatServletWebServerFactory servletContainer(){
//        TomcatServletWebServerFactory tomcat=new TomcatServletWebServerFactory();
//        Connector ajpConnector=new Connector("AJP/1.3");
//        ajpConnector.setPort(8009);
//        ajpConnector.setSecure(false);
//        ajpConnector.setAllowTrace(false);
//        ajpConnector.setScheme("http");
//        ((AbstractAjpProtocol)ajpConnector.getProtocolHandler()).setSecretRequired(false);
//        tomcat.addAdditionalTomcatConnectors(ajpConnector);
//        return tomcat;
//    }
}
